package com.woniu.service.impl;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.woniu.dao.CarManagerDao;
import com.woniu.dao.ClientMortgageInfoDao;
import com.woniu.entity.*;
import com.woniu.service.CarManagerService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Service
public class CarManagerServiceImpl implements CarManagerService {

    @Resource
    @Qualifier("carManagerDao")
    CarManagerDao carManagerDao;

    @Resource
    @Qualifier("clientMortgageInfoDao")
    ClientMortgageInfoDao clientMortgageInfoDao;

    @Override
    public List<CarManager> findAll(CarManager carManager) {
        List<CarManager> all = carManagerDao.findAll(carManager);
        for (CarManager ca:all){

            Integer clientMortgageInfoId=ca.getClientMortgageInfoId();
            ClientMortgageInfo clientMortgageInfo=clientMortgageInfoDao.findCarId(clientMortgageInfoId);
            if(Objects.nonNull(clientMortgageInfo)){
                Integer id=clientMortgageInfo.getId();
                ca.setId(id);
                String clientName=clientMortgageInfo.getClientName();
                ca.setClientName(clientName);
                String borrowStatus=clientMortgageInfo.getBorrowStatus();
                ca.setBorrowStatus(borrowStatus);
                String source=clientMortgageInfo.getSource();
                ca.setSource(source);
                String clientPhone=clientMortgageInfo.getClientPhone();
                ca.setClientPhone(clientPhone);
            }else {
                ca.setId(0);
                ca.setClientName("未知");
                ca.setBorrowStatus("未知");
                ca.setSource("未知");
                ca.setClientPhone("未知");
            }
            //System.out.println("当前"+hm.toString());
        }

        return all;
    }

    @Override
    public CarManager findOne(String id) {
        CarManager list = carManagerDao.findOne(id);
        return list;
    }

    @Override
    public List<CarManager> exportCarList() {
        return carManagerDao.exportCarList();
    }
}
